<?php

require 'DB.php';
$connection = new DB();
$data = $connection->get_all('select * from data order by rand() limit 5');

//从数据库中获取记录
$keys = array_rand($data, 5);

$json = array();
foreach ($keys as $key)
{
    $json[] = $data[$key];
}
//转换为json字符串
echo json_encode($json);
?>